home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5849 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  50 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help With Pointers
  5. Date: Wed, 21 Feb 96 14:45:02 GMT
  6. Organization: none
  7. Message-ID: <824913902snz@genesis.demon.co.uk>
  8. References: <4g67cj$6cv@hobbes.compusult.nf.ca>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4g67cj$6cv@hobbes.compusult.nf.ca>
  15.            bryan@public.compusult.nf.ca "Barry A. Ryan" writes:
  16.  
  17. >Hi
  18. >
  19. >Is there any way to assign a char pointer to a float pointer?
  20.  
  21. This is generally dangerous for alignment reasons - it is a much better
  22. idea to assign a float pointer to a char pointer.
  23.  
  24. >I had to do some byte rotation on binary data.  I rotated 
  25. >the characters and know want to point a float at the first
  26. >character position to read back a 4 byte float.
  27.  
  28. Consider:
  29.  
  30.     float value;
  31.     char *ptr = (char *) &value;
  32.  
  33. You can now consider ptr as pointing to the first element of an array of
  34. chars indexed from 0 to sizeof(float)-1.
  35.  
  36. >I'am actually trying to read SGI binary data with a PC.  I've been told
  37. >that the SGI bytes ( not bits ) are rotated versus a PC.  Any help 
  38. >would be appreciated. Are the bytes rotated?
  39.  
  40. I don't know for certain but most likely the byte order is simply reversed
  41. (big-endian vs. little endian) assuming that they are otherwise compatible.
  42. Using the pointer set up above it would be very easy to copy the bytes
  43. into the target float in the order you require.
  44.  
  45. -- 
  46. -----------------------------------------
  47. Lawrence Kirby | fred@genesis.demon.co.uk
  48. Wilts, England | 70734.126@compuserve.com
  49. -----------------------------------------
  50.